import * as types from "../types/editAddressTypes";

const initialState = {
  loading: false,
  error: undefined,
  success: false,
  realName: "",
  mobile: "",
  area: "",
  addressDetail: "",
  setDefault: false,
};

export default function editAddressReducer(state = initialState, action) {
  switch (action.type) {
    case types.ADDRESS_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.NEWADDRESS_DONE:
      return {
        ...state,
        loading: false,
        success: true,
      };
    case types.NEWADDRESS_ERROR:
      return {
        ...state,
        loading: false,
        error: action.error,
      };
    case types.EDITADDRESS_DONE:
      return {
        ...state,
        loading: false,
        success: true,
      };
    case types.EDITADDRESS_ERROR:
      return {
        ...state,
        loading: false,
        error: action.error,
      };
    case types.ADDRESS_INPUT_NAME:
      return {
        ...state,
        realName: action.realName,
      };
    case types.ADDRESS_INPUT_MOBILE:
      return {
        ...state,
        mobile: action.mobile,
      };
    case types.ADDRESS_CHOOSE_AREA:
      return {
        ...state,
        area: action.area,
      };
    case types.ADDRESS_INPUT_ADDRESSDETAIL:
      return {
        ...state,
        addressDetail: action.addressDetail,
      };
    case types.ADDRESS_EDIT_SETDEFAULT:
      return {
        ...state,
        setDefault: action.setDefault,
      };
    case types.EDITADDRESS_INITADDRESS:
      return {
        ...state,
        realName: action.realName,
        mobile: action.mobile,
        area: action.area,
        addressDetail: action.addressDetail,
        setDefault: action.setDefault,
      };
    case types.EDITADDRESS_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
